package net.xdclass.demo.controller;

import net.xdclass.demo.controller.request.VisitRecordPageRequest;
import net.xdclass.demo.controller.request.VisitTrendQueryRequest;
import net.xdclass.demo.model.JsonData;
import net.xdclass.demo.model.VisitStatsDO;
import net.xdclass.demo.service.VisitStatsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 小滴课堂,愿景：让技术不再难学
 *
 * @Description
 * @Author 二当家小D
 * @Remark 有问题直接联系我，源码-笔记-技术交流群
 * @Version 1.0
 **/

@RestController
@RequestMapping("/api/v1/data")
public class DataController {

    @Autowired
    private VisitStatsService visitStatsService;

    @RequestMapping("page")
    public JsonData queryVisitRecord(@RequestBody VisitRecordPageRequest pageRequest){

        Map<String, Object> map = visitStatsService.pageVisitRecord(pageRequest);
        return JsonData.buildSuccess(map);

    }


    /**
     * 访问趋势
     * @return
     */
    @RequestMapping("trend")
    public JsonData queryVisitTrend(@RequestBody VisitTrendQueryRequest queryRequest){

        List<VisitStatsDO> list = visitStatsService.queryVisitTrend(queryRequest);

        return JsonData.buildSuccess(list);
    }



}
